home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
LOGIC Apps
/
Logic-APPLE_II_APPS.iso
/
mac
/
LOGIC Apple II 5.25" Library - ProDOS
/
PRO041.dsk
/
QUICK.APP.txt
< prev
next >
Wrap
Text File
|
2012-02-16
|
612b
|
35 lines
"QUICK SORT"
DIM ST(30,1) : REM MOVE THIS TO THE BEGINNING OF YOUR PROGRAM
SP = 0 : ST(0,0) = 0
SF = -1 : ST(0,1) = NI
DO
L = ST(SP,0) : R = ST(SP,1) : SP = SP - 1
DO
LI = L : RI = R : SA = SA((L + R) / 2)
DO
WHILE SA(LI) < SA
LI = LI + 1
WEND
WHILE SA(RI) > SA
RI = RI - 1
WEND
LONG IF LI <= RI
SWAP SA(LI), SA(RI)
LI = LI + 1 : RI = RI - 1
END IF
UNTIL LI > RI
LONG IF (R - LI) > (RI - L)
LONG IF L < RI
SP = SP + 1 : ST(SP,0) = L : ST(SP,1) = RI
END IF
L = LI
XELSE
LONG IF LI < R
SP = SP + 1 : ST(SP,0) = LI : ST(SP,1) = R
END IF
R = RI
END IF
UNTIL R <= L
UNTIL SP = -1
RETURN : REM QUICKSORT FINISHED HERE